<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!--"http://127.0.0.1:8080/index/GetCoreLoad?cpu=0&core=0"-->

<html>
    <head>
        <meta name="generator" content="HTML Tidy, see www.w3.org">
<script type="text/javascript" src=
"https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
        
</script>
<script type="text/javascript">
                        
                                var t;
                                var cpuRows;
                                var gpuRows;
                                var numberOfCPUs;
                                var numberOfCores;
                                var parsedData;
                                var go = false;

                                function start() {
                                    if (!go) {
                                        go = true;
                                        timedPoll();
                                    }

                                }

                                function stop() {
                                    go = false;
                                }
                                function init() {
                                    var cpuTable;
                                    var gpuTable;
                        
                                    buildTables();

                        
                                }
                        
                                function timedPoll() {
                        
                                    pollForData();
                                    t = setTimeout("timedPoll()", 2000);
                                }
                        
                                function pollForData() {
                                    if (!go) {
                                        return;
                                    }
                                    var index;
                                    $.getJSON("http://10.1.1.21:8080/index/GetAllCoreDataJ?cpu=0", function (data) {
                                        // document.write(data);
                                        parsedData = jQuery.parseJSON(data);
                                        for (index = 0; index < numberOfCores; index++) {
                                            cpuRows[index + 1].getElementsByTagName('td')[1].innerHTML = roundNumber(parsedData.Cores[index].LoadCurrent, 2);
                                            cpuRows[index + 1].getElementsByTagName('td')[2].innerHTML = roundNumber(parsedData.Cores[index].TemperatureCurrent, 2);
                                        }
                                    });
                        
                                    $.getJSON("http://10.1.1.21:8080/index/GetAllGPUDataJ?gpu=0", function (data) {
                                        //document.write(data);
                                        parsedData = jQuery.parseJSON(data);
                                       // gpuRows[1].getElementsByTagName('td')[1].innerHTML = roundNumber(parsedData.LoadCurrent, 2);
                                       // gpuRows[1].getElementsByTagName('td')[2].innerHTML = roundNumber(parsedData.TemperatureCurrent, 2);

                                    });

                                }
                        
                        
                                function setHeadings() {
                                    $.getJSON("http://10.1.1.21:8080/index/GetAllCoreDataJ?cpu=0", function (data) {
                                        // document.write(data);
                                        parsedData = jQuery.parseJSON(data);
                                        cpuRows[0].getElementsByTagName('td')[0].innerHTML = parsedData.Name;

                                    });

                                    cpuRows[0].getElementsByTagName('td')[1].innerHTML = "Load";
                                    cpuRows[0].getElementsByTagName('td')[2].innerHTML = "Temperature";
                                    cpuRows[0].getElementsByTagName('td')[3].innerHTML = "Max Load";
                                    cpuRows[0].getElementsByTagName('td')[4].innerHTML = "Max Temp";
                        
                                    $.getJSON("http://10.1.1.21:8080/index/GetAllGPUDataJ?gpu=0", function (data) {
                                        //document.write(data);
                                        parsedData = jQuery.parseJSON(data);
                                       // gpuRows[0].getElementsByTagName('td')[0].innerHTML = parsedData.Name;             
                     
                                    });
                                }
                        
                                function roundNumber(num, dec) {
                                    var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
                                    return result;
                                }            
                            
                                function buildTables(){
                                    // referred to: https://developer.mozilla.org/en/traversing_an_html_table_with_javascript_and_dom_interfaces
                                    // only supporting one CPU and one GPU for now

                                    var numberOfGPUs = 1;
                                    var numberOfSensors = 4; // load, temp, load max, temp max

                                    $.getJSON("http://10.1.1.21:8080/index/GetCoreCountJ?cpu=0", function (data) {
                                        parsedData = jQuery.parseJSON(data);
                                        numberOfCores = parsedData.Count;

                                        // build the CPU table
                                        var body = document.getElementsByTagName("body")[0];
                                        var cpuTable = document.createElement("table");
                                        cpuTable.setAttribute("id", "cpuTable");
                                        var cpuBody = document.createElement("tbody");
                                        // create a row for each core plus one for headings
                                        for (var i = 0; i <= numberOfCores; i++) {
                                            var row = document.createElement("tr");
                                            for (var j = 0; j <= numberOfSensors; j++) {
                                                // Create a <td> element and a text node, make the text
                                                // node the contents of the <td>, and put the <td> at
                                                // the end of the table row
                                                var cell = document.createElement("td");
                                                var cellText = document.createTextNode("no data");
                                                cell.appendChild(cellText);
                                                row.appendChild(cell);
                                            }

                                            // add the row to the end of the table body
                                            cpuBody.appendChild(row);
                                        }
                                        // put the <tbody> in the <table>
                                        cpuTable.appendChild(cpuBody);
                                        // appends <table> into <body>
                                        body.appendChild(cpuTable);
                                        // sets the border attribute of tbl to 2;
                                        cpuTable.setAttribute("border", "2");

                                        cpuTable = document.getElementById("cpuTable");
                                        cpuRows = cpuTable.getElementsByTagName("tr");

                                        setHeadings();

                                        //       gpuTable = document.getElementById("gpuTable");
                                        //       gpuRows = gpuTable.getElementsByTagName('tr');
                                        for (i = 0; i <= numberOfCores; i++) {

                                            cpuRows[i+1].getElementsByTagName('td')[0].innerHTML = "Core " + i;
                                        }

                                    });   

                                    
                                }
         
        
</script>

        <title></title>
    </head>

    <body onload="init()">
        <form>
            <input type="button" value="Start" onclick="start()"/>
             <input type="button" value="Stop" onclick="stop()"/>
        </form>
    </body>
</html>

